/*
 * Copyright (c) 2001 Boris Pruessmann and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Common Public License v0.5
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors:
 *    Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.p4eclipse.ui.model;

import net.sourceforge.p4eclipse.core.resources.RemoteFolder;
import net.sourceforge.p4eclipse.ui.PerforceUIPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.team.core.TeamException;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.model.IWorkbenchAdapter;

/**
  * @version 	1.0
  * @author		<a href="mailto:bpruessmann@users.sourceforge.net">Boris Pruessmann</a>
  */
public class RemoteFolderElement implements IWorkbenchAdapter
{

	/*
	 * @see IWorkbenchAdapter#getChildren(Object)
	 */
	public Object[] getChildren(Object object)
	{
		Object[] result = new Object[0];
		try
		{
			if (!(object instanceof RemoteFolder)) 
				return null;
	
			RemoteFolder folder = (RemoteFolder)object;				
			result = folder.members(new NullProgressMonitor());
		}
		catch (TeamException e)
		{
			PerforceUIPlugin.getPlugin().log(e.getStatus());
		}
		
		return result;
	}

	/*
	 * @see IWorkbenchAdapter#getImageDescriptor(Object)
	 */
	public ImageDescriptor getImageDescriptor(Object object)
	{
		if (!(object instanceof RemoteFolder)) 
			return null;
			
		RemoteFolder remoteFolder = (RemoteFolder)object;
		if (remoteFolder.getParent() != null)			
			return PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
		else
			return PerforceUIPlugin.getPlugin().getImageDescriptor(PerforceUIPlugin.IMG_ROOTELEMENT);
	}

	/*
	 * @see IWorkbenchAdapter#getLabel(Object)
	 */
	public String getLabel(Object object)
	{
		if (!(object instanceof RemoteFolder)) 
			return null;
		
		RemoteFolder folder = (RemoteFolder)object;		
		return folder.getName();
	}

	/*
	 * @see IWorkbenchAdapter#getParent(Object)
	 */
	public Object getParent(Object o)
	{
		return null;
	}

}
